# -*- coding:utf-8 -*-
# @Time: 2020/9/7 16:31
# @Author: gupeng
# @File: id_generator.py
# @Desc: 自增id--incrby测试
class IdGenerator:
    def __init__(self, client, key):
        self.client = client
        self.key = key

    def product(self):
        """
        创建并返回下一个id
        :return: 当前值
        """
        return self.client.incrby(self.key)

    def reserve(self, n):
        """
        创建id并设置初始值
        :param n: 初始值
        :return: 当前值
        """
        return self.client.set(self.key, n, nx=True) is True
